<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>11-切换组件</title>
    <script src="../js/vue.js"></script>
</head>
<body>
<!--1. 准备一个容器-->
<div id="app">
    <login v-if="flag"></login>
    <register v-else></register>
    <button @click="uchange()">点我切换按钮</button>
</div>
    <template id="temp1">
        <div>
            <form action="#">
                <p>用户名: <input type="text" name="username" placeholder="请输入登录的用户名" v-model="username"></p>
                <p>密码: <input type="password" name="password" placeholder="请输入密码" v-model="password"></p>
                <button @click="login()">登录</button>
            </form>
        </div>
    </template>

    <template id="temp2">
        <div>
            <form action="#">
                <p>用户名: <input type="text" name="username" placeholder="请输入注册的用户名" v-model="username"></p>
                <p>密码: <input type="password" name="password" placeholder="请输入注册的密码" v-model="password"></p>
                <button @click="register()">注册</button>
            </form>
        </div>
    </template>

<script>
    const login = Vue.extend({
        template:"#temp1",
        data(){
            return{
                username:undefined,
                password:undefined,
            }
        },
        methods:{
            login:function () {
                alert("登录");
            }
        },
    });

    const register = Vue.extend({
        template:"#temp2",
        data(){
            return{
                username:undefined,
                password:undefined,
            }
        },
        methods:{
            register:function () {
                alert("注册");
            }
        },
    });

    Vue.component("login",login);
    Vue.component("register",register);

    let vm = new Vue({
        el: "#app",
        data: {
            flag:true,
        },
        methods:{
            uchange:function () {
                this.flag=!this.flag;
            }
        }
    });
</script>

</body>
</html>